import { createRouter } from 'uni-mini-router'
// 导入pages.json
import pagesJson from '../pages.json'
// 引入uni-parse-pages
import pagesJsonToRoutes from 'uni-parse-pages'
import {useSystemStore} from "@/store/modules/system";
// 生成路由表
const routes = pagesJsonToRoutes(pagesJson)
const router = createRouter({
    routes: [...routes] // 路由表信息
})

//登录白名单页面
const whiteList = ['/pages/passwordLogin/index','/pages/login/index']
//全局路由前置守卫
router.beforeEach((to, from, next) => {
    const { hasLogin } = useSystemStore()
    //跳转页面不在白名单内
    if(!whiteList.includes(to.path)){
        hasLogin()&& next()
        return
    }
    // next入参 false 以取消导航
    next()
})

// 全局路由后置守卫
router.afterEach((to, from) => {
    console.log(to)
    console.log(from)
})
export default router